﻿using Omnia.DataModels;
using System.Linq;
using System.Collections.Generic;
using System.Collections.ObjectModel;

namespace Omnia.ViewModels
{
    public class CategoryTransactionViewModel : CategoryViewModel
    {
        private string guid;
        public string Guid
        {
            get { return guid; }
            set
            {
                guid = value;
                RaisePropertyChanged(() => Guid);
                if (Guid != null)
                {
                    CurrentShowItem = Database.CollectionOfCategories.FirstOrDefault(c => c.Guid == Guid);
                }
                RaisePropertyChanged(() => CurrentShowItem);
                RaisePropertyChanged(() => FetchedTransactionCollection);
            }
        }

        private CategoryInfo currentShowItem = new CategoryInfo();
        public CategoryInfo CurrentShowItem
        {
            get { return currentShowItem; }
            set
            {
                currentShowItem = value;
                RaisePropertyChanged(() => CurrentShowItem);
            }
        }

        public ObservableCollection<TransactionInfo> FetchedTransactionCollection
        {
            get
            {
                return new ObservableCollection<TransactionInfo>(Database.CollectionOfTransactions.Where(t => t.CategoryGuid == Guid));
            }
        }
    }
}
